//
//  Remind_ListViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/11/8.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Remind_ListViewController.h"

#import "Date_listTableViewCell.h"

@interface Remind_ListViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

//保存位置
@property (nonatomic, assign) NSInteger index_number;

@end

@implementation Remind_ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    self.index_number = 0;
    
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"提醒";
    _topView.backgroundColor = navi_bar_bg_color;
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 100, 15)];
    lbl_return.text = @"取消";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 100, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右完成
    UIButton * btn_Edit = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_Edit.frame = CGRectMake(SCREEN_WIDTH - 5 - 50, 20 + 7, 50, 30);
    [btn_Edit setTitle:@"完成" forState:(UIControlStateNormal)];
    [btn_Edit setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_Edit.titleLabel.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:btn_Edit];
    [btn_Edit addTarget:self action:@selector(btn_EditAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右完成
- (void )btn_EditAction:(UIButton *)sender
{
    //    NSLog(@"点击右完成");
    
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Date_listTableViewCell class] forCellReuseIdentifier:@"cell_date"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Date_listTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_date" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.name.text = [NSString stringWithFormat:@"%ld分钟后",indexPath.row + 1];
    
    cell.correct.hidden = YES;
    cell.name.textColor = [UIColor grayColor];
    
    if(indexPath.row == self.index_number)
    {
        cell.name.textColor = [UIColor colorWithRed:90/255.0 green:167/255.0 blue:239/255.0 alpha:1.0];
        cell.correct.hidden = NO;
    }
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.index_number = indexPath.row;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新tableView(记住,要更新放在主线程中)
        [self.tableView reloadData];
    });
}

























@end
